<%--
  Created by IntelliJ IDEA.
  User: LiuLong
  Date: 2020/9/13
  Time: 10:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
<%--    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>--%>
    <script src="js/jquery-3.5.1.js"></script>
    <script>
        //页面加载,绑定单击事件
        $(function () {
            $("#btn").click(function () {
                // alert("hello");
                $.ajax({
                    //编写json格式,设置属性和值
                    url: "user/testAjax",
                    contentType:"application/json;charset=UTF-8",
                    data:'{"username":"刘龙","password":"123","age":30}',
                    /*返回数据的格式*/
                    dataType: "json",
                    type: "post",
                    success:function (data) {
                        //服务daunt响应的json数据,进行解析
                        alert(data);
                        alert(data.username);
                        alert(data.password);
                        alert(data.age);
                    }
                });
            });
        });
    </script>
    <script>
        //页面加载,绑定单击事件
        $(function () {
            $("#btn2").click(function () {
                $.ajax({
                    //编写json格式,设置属性和值
                    url: "user/testAjax2",
                    contentType: "application/json;charset=UTF-8",
                    data: '{"username": "刘龙", "password": "123", "age":22}',
                    /*返回数据的格式*/
                    dataType: "json",
                    type: "post",
                    success: function (datas) {
                        //服务器响应的json数据
                        alert(datas);
                        alert(datas.username);
                        alert(datas.password);
                        alert(datas.age);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <a href="user/testString">testString</a><br/>

    <a href="user/testVoid">请求转发</a><br/>

    <a href="user/testVoid2">重定向</a><br/>

    <a href="user/testVoid3">直接响应</a><br/>

    <a href="user/testModelAndView">testModelAndView</a><br/>

    <a href="user/testForwardOrRedirect">testForwardOrRedirect</a><br/>

    <button id="btn">发送ajax的请求</button><br/>

    <button id="btn2">发送ajax的请求2</button>
</body>
</html>
